<template>
	<view class="">
		<!-- 头部部分 -->
		<view class="shop-list">
			<view class="shop-item" v-for="(items,id) in orderData" :key="id" v-if="items.order_id == item.order_id" @tap="goOrderDetial(items,index)">
				<label class="radio">
					<image class="shop-img" :src="items.imgUrl" mode=""></image>
				</label>
				<view class="shop-text">
					<view class="shop-name-number">
						<text class="shop-name">{{items.goods_name}}</text>
						<text v-if="disable">*{{items.goods_num}}</text>
					</view>
					<view class="shop-price">
						<text class="money">￥{{items.goods_price}}</text>
					</view>
				</view>
			</view>
			<view class="foot">
				<view>
					<text>合计：</text>
					<text class="account">￥{{item.unitPrice}}</text>
				</view>
				<view class="butn">
					<view class="" v-if="item.order_status == 1">
						<view class="byagin" @tap.stop="goPayment(item,index)">去付款</view>
					</view>
					<view class="btn-delivery-cancle" v-if="item.order_status == 2">
						<view class="byagin" @tap.stop="delivery(item,index)">配送</view>
						<view class="byagin" @tap.stop="cancleOrder(item,index)">取消订单</view>
					</view>
					<view v-if="item.order_status == 3">
						<view class="byagin" @tap.stop="confirmReceipt(item,index)">确认收货</view>
					</view>
					<view class="btn-item" v-if="item.order_status == 4">
						<view class="review" @tap.stop="delOrder(item,index)">删除订单</view>
						<view class="review" @tap.stop="goReview(item,index)">去评价</view>
						<view class="byagin" @tap="bayAgain(item,index)">再次购买</view>
					</view>
					<view class="" v-if="item.order_status == 5">
						<view class="byagin"@tap.stop="delOrder(item,index)">删除订单</view>
					</view>
					<view class="" v-if="item.order_status == 6">
						<view class="byagin"@tap.stop="delOrder(item,index)">删除订单</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import $http from '../../common/api/request.js'
	export default {
		props:{
			orderData:Array,
			item:Object,
			disable:Boolean,
			index:Number
		},
		onLoad() {
			
		},
		methods:{
			goOrderDetial(items,index){
				// disable:true 跳转订单详情页面   false跳转商品详情页面
				let info = {
					id:items.shopId,
					shopType:items.type,
				}
				if(this.disable){
					uni.navigateTo({
						url:'/pages/order-detial/order-detial?data='+JSON.stringify(this.item)+''
					})
				}else{
					uni.navigateTo({
						url:"/pages/detial/detial?info="+JSON.stringify(info)+""
					})
				}
				
			},
			bayAgain(item,index){
				console.log(item);
			},
			// 去付款 ，成功 --》  删除订单中的对应数据
			goPayment(items,index){
				uni.showModal({
					content:"确认付款吗",
					success: (res) => {
						if(res.confirm == true){
							uni.navigateTo({
								url:`/pages/payment/payment?shopObj=${JSON.stringify(this.item)}`
								// url:"/pages/payment/payment?shopObj="+JSON.stringify(this.item)+"&ItemObj = "+JSON.stringify(items)+""
							})
							uni.$on('paySuccess',function(data){
								if(data.status == true){
									$http.request({
										url:'/submitOrder',
										method:'POST',
										header:{
											token:true
										},
										data:{
											orderId:item.order_id
										}
									}).then((res)=>{
										uni.$emit('update',{id:this.current})
										uni.navigateTo({
											url:"/pages/payment-success/payment-success"
										})
									}).catch(()=>{
										uni.showToast({
											title:"请求失败",
											icon:'none'
										})
									})
								}
							})
							
						}else{
							uni.showToast({
								title:"快去购买你中意的物品吧！",
								icon:'none'
							})
						}
					}
				})
				uni.$off('paySuccess')
			},
			// 配送
			delivery(item,index){
				uni.showModal({
					content:"确认配送吗",
					success: (res) => {
						if(res.confirm == true){
							$http.request({
								url:'/delivery',
								method:'POST',
								header:{
									token:true
								},
								data:{
									orderId:item.order_id
								}
							}).then((res)=>{
								if(res.success == true){
									uni.$emit('update',{id:index})
								}
							}).catch(()=>{
								uni.showToast({
									title:"请求失败",
									icon:'none'
								})
							})
						}
					}
				})
			},
			// 取消订单
			cancleOrder(item,index){
				uni.showModal({
					content:"确认取消订单",
					success: (res) => {
						if(res.confirm == true){
							$http.request({
								url:'/CancleOrder',
								method:'POST',
								header:{
									token:true
								},
								data:{
									orderId:item.order_id
								}
							}).then((res)=>{
								uni.$emit('update',{id:this.current})
							}).catch(()=>{
								uni.showToast({
									title:"请求失败",
									icon:'none'
								})
							})
						}
					}
				})
			},
			// 确认收货
			confirmReceipt(item){
				uni.showModal({
					content:"确认收货吗",
					success: (res) => {
						if(res.confirm == true){
							$http.request({
								url:'/confirmReceipt',
								method:'POST',
								header:{
									token:true
								},
								data:{
									orderId:item.order_id
								}
							}).then((res)=>{
								uni.$emit('update',{id:this.current})
							}).catch(()=>{
								uni.showToast({
									title:"请求失败",
									icon:'none'
								})
							})
						}
					}
				})
			},
			// 删除订单
			delOrder(item){
				uni.showModal({
					content:"确认删除订单吗",
					success: (res) => {
						if(res.confirm == true){
							$http.request({
								url:'/deleteOrder',
								method:'POST',
								header:{
									token:true
								},
								data:{
									orderId:item.order_id
								}
							}).then((res)=>{
								if(item.order_status == 4){
									uni.$emit('update',{id:this.current})
								}else if(item.order_status == 5){
									uni.$emit('update',{id:5})
								}
							}).catch(()=>{
								uni.showToast({
									title:"请求失败",
									icon:'none'
								})
							})
						}
					}
				})
			},
			// 去评价
			goReview(item,index){
				uni.navigateTo({
					url:'/pages/goods_review/goods_review?data='+JSON.stringify(item)+''
				})
			}
		}
	}
</script>

<style scoped>
	.shop-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-top: 1rpx solid #efefef;
	}
	.shop-img{
		width: 150rpx;
		height: 150rpx;
	}
	.shop-text{
		flex: 1;
		height: 150rpx;
		padding: 15rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}
	.shop-price {
		display: flex;
		justify-content:space-between;
		align-items: center;
	}
	.shop-name-number{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.foot{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.byagin{
		display: flex;
		justify-content: center;
		align-items: center;
		color: white;
		background-color: #ff0000;
		width: 100rpx;
		height: 50rpx;
		border-radius: 5rpx;
		font-size: 22rpx;
	}
	.review{
		display: flex;
		justify-content: center;
		align-items: center;
		color: #636263;
		width: 100rpx;
		height: 50rpx;
		border: 2rpx solid #cbd3d6;
		border-radius: 5rpx;
		font-size: 22rpx;
	}
	.btn-delivery-cancle{
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 240rpx;
	}
	.btn-item{
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 340rpx;
	}
	.account{
		color: red;
	}
</style>